import { defineStore } from "pinia";
export const useUserStore = defineStore({
    id: "user",
    //id,模块名称
    state: () => {
        return {
            userInfo: null
        };
    },
    actions: {
        setUserInfo(userInfo) {
            this.userInfo = {
                userName: "",
                nickName: "",
                id: "",
                sex: "",
                edu: "",
                tele: "",
                avatar:""
            }
            console.log("userInfo::", userInfo)
            this.userInfo.userName = userInfo.userName;
            this.userInfo.nickName = userInfo.nickName;
            this.userInfo.password = userInfo.password;
            this.userInfo.sex = userInfo.sex;
            this.userInfo.edu = userInfo.edu;
            this.userInfo.tele = userInfo.tele;
            this.userInfo.id = userInfo.id;
            this.userInfo.avatar = userInfo.avatar;
        },
        logout() {
            this.userInfo = null
        },
    },
    // 开启数据缓存
    persist: {
        enabled: true,
        //表示开启持久化保存
        strategies: [
            {
                key: "user",
                storage: localStorage,
            },
        ],
    },
});

